cmake_minimum_required(VERSION 3.10)
project(grpcDemo C CXX)

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Debug")
endif()

# find_package(gRPC  REQUIRED )
# ubuntu通过apt包管理器安装的grpc没有findgrpc.cmake这样的文件，但是有.pc这样的文件
# windows通过vcpkg库管理器安装的grpc有gRPCConfig.cmake,但是没有.pc文件
# Linux上用 PkgConfig 中 pkg_check_modules 获取库;windows上直接通过find_package查找;

find_package(PkgConfig REQUIRED)
find_package(Protobuf REQUIRED)

# 指定 C++ 标准为 C++17  
set(CMAKE_CXX_STANDARD 17)  
set(CMAKE_CXX_STANDARD_REQUIRED True)

if(WIN32)
  set(PROTO_PATH proto/win)
  find_package(gRPC CONFIG REQUIRED)
  get_target_property(GRPC_CPP_PLUGIN gRPC::grpc_cpp_plugin LOCATION)
  set(GRPC_LIBRARIES gRPC::grpc++) 
else()
   set(PROTO_PATH proto/linux)
#  find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin REQUIRED)
  pkg_check_modules(GRPC REQUIRED grpc++)
endif()

include_directories(${PROTO_PATH})  

set(SRCS 
    main.cpp  
    ${PROTO_PATH}/hello.grpc.pb.cc 
    ${PROTO_PATH}/hello.pb.cc
)

set(SRCS_Client 
    client.cpp  
    ${PROTO_PATH}/hello.grpc.pb.cc 
    ${PROTO_PATH}/hello.pb.cc
)

add_executable(grpcServer ${SRCS})
target_link_libraries(grpcServer  ${Protobuf_LIBRARIES} ${GRPC_LIBRARIES} )

add_executable(grpcClient ${SRCS_Client})
target_link_libraries(grpcClient ${Protobuf_LIBRARIES} ${GRPC_LIBRARIES} )





